onsubmit="return check();"返回false后表单仍然提交

来源:百度知道 编辑:UC知道 时间:2024/05/12 10:29:20
表单定义:
<form name="form1" method="POST" action="a.asp" onsubmit="return checkform();">
<input type="text" name="thistimemoney" size="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">
<input type="submit" value="确定并开始" name="submit">
</form>
函数定义:
<script language=javascript>
function checkform(){
if (form1.thistimemoney.value==""){
alert("你没输入钱数啊!");
from1.thistimemoney.focus();
return(false);
}
}
</script>

不是说如果不合法就不会提交出去吗?为什么这个也有提示但是点确定后还是转到了action的页面?
二楼我试过可以了,能说说为什么吗?

<form name="form1" method="POST" action="a.asp" onsubmit="return checkform();">
<input type="text" name="thistimemoney" id="yanzi" size="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">
<input type="submit" value="确定并开始" name="submit">
</form>
函数定义:
<script language=javascript>
function checkform(){
if (form1.thistimemoney.value==""){
alert("你没输入钱数啊!");
document.getElementById("yanzi").focus();
return(false);
}
}
</script>

改成这样应该就没问题了 ...

跟我的有点区别哦 不知道是不是
你要是满足了if 会不会有对话框弹出呢啊?
你看下面的试试

<script language=javascript>
function checkform(){
if (document.form1.thistimemoney.value==""){
window.alert("你没输入钱数啊!&